/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.imgs;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * <p>Project: javaseapp - Img4
 * <p>Powered by webrx On 2021-08-13 11:35:35
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Img4 {
    public static void main(String[] args) {
        String src = "images/abc.png";
        try {
            BufferedImage i = ImageIO.read(new File(src));
            //转换黑白灰度效果
            int w = i.getWidth();
            int h = i.getHeight();

            //type 是10 代表灰度模式，不能有彩色。
            BufferedImage dst = new BufferedImage(w, h, 10);
            var g = dst.createGraphics();
            g.drawImage(i, 0, 0, null);
            ImageIO.write(dst, "png", new File("images/abc_gray.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
